<?php
namespace app\index\controller;
use think\Session;
use think\Controller;
use think\Db;
class Api extends Controller
{
    public function index()
    {
        return jsonp(['code'=>0,'msg'=>'ok','data'=>null]);
    }
    //API 列出门店
    public function getClinic(){
    	$cdata=db("clinic")->where("id","<>",0)->select();
    	return jsonp(['code'=>0,'msg'=>'ok','data'=>$cdata]);
    }
    //根据门店查找医生
    public function getDoctorByCid(){
    	$cdata=db("doctor")->field("id,name,phone")->where("clinic",input("id"))->select();
    	return jsonp(['code'=>0,'msg'=>'ok','data'=>$cdata]);
    }
    //查找文章列表
    public function getArtcleList(){
    	$cdata=Db::query("SELECT article_id,title,time,nikename,desp,cover_img FROM article a left join admin b on a.author_id = b.id");
    	return jsonp(['code'=>0,'msg'=>'ok','data'=>$cdata]);
    }
    //获取文章内容
    public function getArticleContent(){
    	$cdata=Db::query("SELECT * FROM article a left join admin b on a.author_id = b.id where article_id=".input("id"));
    	return jsonp(['code'=>0,'msg'=>'ok','data'=>$cdata]);
    }
    public function submitAppo(){
    	$data=array(
    		"doctor_id"=>input("did"),
    		"name"=>input("name"),
    		"tel"=>input("phone"),
    		"time"=>input("time"),
    		"ask"=>input("ask"),
    		"state"=>0
    		);
    	$id=db("appointment")->insertGetId($data);
    	if($id) return jsonp(['code'=>0,'msg'=>'ok','data'=>["appoId"=>$id]]);
    	else return jsonp(['code'=>-1,'msg'=>'预约失败','data'=>null]);
    }
    public function getCustomerDeteil(){
    	$name=input('name');
    	$phone=input('phone');
    	$res=db::query("select c.id,c.name,c.tel,c.gender,cl.name as cname from customer c LEFT JOIN clinic cl on c.clinic=cl.id WHERE c.name='".$name."' AND c.tel='".$phone."'");
    	foreach($res as $key=>$val){
    		$res[$key]["case"]=db("case")->where("uid",$val["id"])->select();
    	}
    	if($res) return jsonp(['code'=>0,'msg'=>'ok','data'=>$res]);
    	else return jsonp(['code'=>-1,'msg'=>'查询失败','data'=>null]);
    }
    
}